package com.wt.admin.domain.vo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;


@Data
public class SocketVO<T> {

    @JsonIgnore
    private ObjectMapper mapper = new ObjectMapper();

    private T data;

    private String type;

    public SocketVO() {
    }

    public SocketVO(String type, T data) {
        this.type = type;
        this.data = data;
    }

    @Override
    public SocketVO<T> clone() {
        try {
            return (SocketVO<T>) super.clone();
        } catch (Exception e) {
            return new SocketVO<T>();
        }
    }

    public SocketVO<T> build(String type, T data) {
        SocketVO<T> clone = this.clone();
        clone.setData(data);
        clone.setType(type);
        return clone;
    }

    public SocketVO<T> build(T data) {
        SocketVO<T> clone = this.clone();
        clone.setData(data);
        clone.setType(type);
        return clone;
    }

}
